package com.ruoyi.pay.refund.wx.util;

import com.alibaba.fastjson.JSON;
import com.ruoyi.pay.refund.util.HttpUtil;
import com.ruoyi.pay.refund.wx.vo.WeChatRefundReturnVO;
import com.ruoyi.pay.refund.wx.vo.WeChatRefundVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 🤙🤙🏼🤙🏽
 * @date 2025 4月 16 11:58
 * @Description
 */
@Component
@Slf4j
public class WXRefundUtil {

    @Resource
    private HttpUtil httpUtil;

    /**
     * 退款接口
     *
     * @param weChatRefundRequestVo
     * @return wxRefundReturnInfoVo
     */
    public WeChatRefundReturnVO refundOrder(WeChatRefundVO weChatRefundRequestVo) {
        //包装请求参数
        String requestData = JSON.toJSONString(weChatRefundRequestVo);
        //接收请求结果并序列化
        WeChatRefundReturnVO weChatRefundResponseVo = httpUtil.wxHttpRequest(
               "POST",
              "https://api.mch.weixin.qq.com/v3/refund/domestic/refunds",
                requestData, WeChatRefundReturnVO.class);
        return weChatRefundResponseVo;
    }
}
